//npm install express
const express = require('express');
const app = express();
const path = require('path');
const url = require('url')

app.get('/s', (req, res) => {
  res.send("这是express服务器的/s接口返回的内容");
});

app.get('/a', (req, res) => {
  res.sendFile(path.resolve('./index.html'));
});

app.get('/getData', (req, res) => {
    var query = url.parse(req.url);
    res.send("你已经成功通过get向getData接口发送了请求");
})

app.post('/postData', (req, res) => {
    var str = "";
    req.on('data', (chunk) => {
        str += chunk;
    });
    req.on('end', () => {
        console.log(str);
        res.send("你已经成功通过post向postData接口发送了请求");
    });
})

app.listen(3001);


//发送get请求的方式
//1.浏览器地址栏 2.form表单的get 3.a标签 4.ajax的get请求
//发送post请求的方式
//1.form表单的post 2.ajax的post请求

//设置淘宝镜像
//npm config set registry https://registry.npmmirror.com/
//npm install express